package TemplateMethod;

public class StringDisplay extends AbstractDisplay{
    private String string;
    private int width;
    public StringDisplay(String string){
        this.string=string;
        this.width=string.getBytes().length;//将字符串的长度保存在字段仲
    }

    @Override
    public void open() {
        printline();
    }
    public void print(){
        System.out.println("|"+string+"|");
    }

    @Override
    public void close() {
        printline();
    }
    private void printline(){
        System.out.println("+");
        for (int i=0;i<width;i++)
        {
            System.out.println("-");
        }
        System.out.println("+");
    }
}
